package indi.zhifa.study2025.test.rabbitmq.rpc.s1.config;

import indi.zhifa.study2025.test.rabbitmq.common.Constant;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitConfig {

    @Bean(name = "s1-request")
    public Queue queue1() {
        return new Queue(Constant.PRC_QUE_REQUEST_S1,true);
    }

    @Bean(name = "default-exchange")
    public DirectExchange psExchange() {
        return new DirectExchange(Constant.DEFAULT_EXCHANGE_NAME);
    }

    @Bean
    public Binding bindingQue1(@Qualifier("s1-request") Queue myQueue, @Qualifier("default-exchange") DirectExchange exchange) {
        return BindingBuilder.bind(myQueue).to(exchange).with(Constant.PRC_QUE_REQUEST_S1);
    }

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        rabbitTemplate.setReplyTimeout(3000);
        return rabbitTemplate;
    }
}
